package util;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class arrayListSet {

    public static void main(String[] args) {


        int[] arr = {1, 4, 8, 2, 22, 144, 23, 53};

        /**
         * 数组转list
         */

        //一、很快捷 但支支持查改  不支持增删。
        List list = Arrays.asList(arr);

        //二、将Arrays.asList(arr) 得返回结果由java.util.Arrays.ArrayList 转化为 java.util.ArrayList 支持增删改查
        ArrayList arrayList = new ArrayList(Arrays.asList(arr));

        //三、Collections转化为最佳方式。
        List ls = new ArrayList(arr.length);
        Collections.addAll(ls, arr);

        //四、stream流
        List<Integer> intList = Arrays.stream(arr).boxed().collect(Collectors.toList());
//        List<Long> longList= Arrays.stream(arr).boxed().collect(Collectors.toList());
//        List<Double> doubleList= Arrays.stream(arr).boxed().collect(Collectors.toList());

        String[] arrays = {"tom", "jack", "kate"};
        List<String> stringList = Stream.of(arrays).collect(Collectors.toList());


        /**
         * 数组转set
         */


        //stream流
        Integer[] arr1 = {1, 4, 2, 67, 22, 9};
        Set<Integer> set = Arrays.stream(arr1).collect(Collectors.toSet());

        //for-each
        String[] numbers = new String[]{"One", "Two", "Three", "One", "Six"};
        Set<String> set1 = new HashSet<>();
        for (String str : numbers) {
            set1.add(str);
        }

        //"Collections.addAll()"方法
        Set<String> set2 = new HashSet<>();
        Collections.addAll(set2, numbers);

        //不推荐，大小固定不能增删
        Set<String> set3 = new HashSet<>(Arrays.asList(numbers));// size=1


        /**
         * list set相互转换
         */
        Set<String> set4 = new HashSet<>(list);
        List list2 = new ArrayList(set4);


        //判断list 中是否含有某个值
        list2.add("1");
        list2.add("2");
        list2.add("3");
        boolean b = list2.stream().anyMatch(m -> m.equals("1"));
        System.out.println(b);

    }

}
